import requests

from util.time_stamp import get_time_stamp
from util.headers import get_headers_init_user_agent
import base64
import random
from urllib.parse import urlencode
import re
import hashlib

user_agent = get_headers_init_user_agent().get("User-Agent")
user_agent_b64 = base64.b64encode(user_agent.encode())
user_agent = user_agent_b64.decode()

d = {
    "method": "GET",
    "timeStamp": get_time_stamp(),
    "User-Agent": user_agent,
    "index": random.randint(1, 1000),
    "channelId": 40009,
    "sVersion": 2,
    "key": "A013F70DB97834C0A5492378BD76C53A"
}

c = urlencode(d)
c = re.sub(r'\s+', '', c)

md5 = hashlib.md5(c.encode()).hexdigest()
d['signKey'] = md5
d.pop('key')
d.pop('method')
# print(d)

d.update({
    "movieId": "18167",
    "orderType": 0,
    "uuid": "19a38c693d4c8-078751b7567c018-26061b51-144000-19a38c693d5c8",
    "WuKongReady": "h5"
}
)



res = requests.get('https://piaofang.maoyan.com/dashboard-ajax/movie', headers=get_headers_init_user_agent(),  params=d)
print(res.json())
